<template>
	<view class="feedback-container">

		<view class="uni-textarea">
			<h4>问题和意见</h4>
			<TnInput type="textarea" v-model="content" placeholder="请填写10字以上的问题描述以便我们提供更好的帮助" height="250"
				:maxlength="200" clearable show-word-limit />

		</view>
		<view class="feedback-submit">
			<button type="default" class="feedback-button" @click="feedbackSubmit()">提交</button>
		</view>
		<tn-notify ref="notifyRef" />
	</view>

</template>

<script lang="ts" setup>
	import { ref,getCurrentInstance } from 'vue'
	import { onLoad } from "@dcloudio/uni-app"
	import TnInput from '@/uni_modules/tuniaoui-vue3/components/input/src/input.vue'
	import { messageForm } from '@/utils/api';
	import type { TnNotifyInstance } from '@/uni_modules/tuniaoui-vue3'
	const notifyRef = ref<TnNotifyInstance>()
	const content = ref()
	const feedbackSubmit = async () => {
		if (!content.value || content.value.length < 10) {
			notifyRef.value?.show({
				msg: '请填写10字以上的问题描述以便我们提供更好的帮助',
				type: 'warning',
			})
			return;
		}
		const { code, msg } = await messageForm(content.value);
		if (code === 1) {
			notifyRef.value?.show({
				msg: '反馈成功',
			})
			setTimeout(() => {
				uni.navigateBack();
			}, 1000)

		} else {
			notifyRef.value?.show({
				msg: msg,
				type: 'warning',
			})
		}
	}
	
	onLoad(() => {
		const { proxy } : any = getCurrentInstance()
		const newMethod = proxy.$wxShare;
		var url = window.location.protocol + "//" + window.location.host;
		const pages = getCurrentPages();
		const link = url + "/#/" + pages[pages.length - 1].route
		newMethod("意见反馈", "", link)
	})
</script>

<style lang="scss" scoped>
	.feedback-container {
		padding: 0 20rpx;

		h4 {
			margin: 20rpx 0;
			color: #333
		}

		.feedback-submit {
			position: fixed;
			bottom: 30rpx;
			left: 0;
			padding: 0 20rpx;
			width: 100%;
		}
	}
</style>